﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Quotation
{
    public class DataTool
    {

        /// <summary>
        /// 格式化，四舍五入
        /// </summary>
        /// <param name="d"></param>
        /// <param name="decimals"></param>
        /// <returns></returns>
        public static Double Round(Double d, int decimals, MidpointRounding mpr = MidpointRounding.AwayFromZero)
        {
            if (double.IsNaN(d))
            {
                return d;
            }
            else
            {
                try
                {
                    decimal dd = (decimal)d;//decimal精度更高，
                    return (double)Math.Round(dd, decimals, mpr);
                }
                catch
                {

                    return Math.Round(d, decimals, mpr);
                }
            }
        }

    }

}
